@extends('admin.base')
@section('body')
    <form class="layui-form col-lg-5" style="margin-top:20px"  enctype="multipart/form-data" method="POST" action="/admin/banner_update">
    <!-- <form class="layui-form col-lg-5" style="margin-top:20px" enctype="multipart/form-data"> -->
        {{ csrf_field() }}    
        @isset($list->picname)
        <div class="layui-form-item" pane>
            <label class="layui-form-label">原Banner</label>
            <div class="layui-input-inline"  style="width:500px;">
                <a href="javascript:void(0);" target="_blank"><img src="/banner/{{$list->picname}}" height="100px"></a>
            </div>
        </div>
        <input type="hidden" name="id" value="{{$list->id}}">
        <div class="layui-form-item">
            <label class="layui-form-label">ICO</label>
            <div class="layui-input-block">
                <input type="file" name="picname" lay-ext="jpg|png|gif" required  lay-verify="required">
            </div>
        </div>
        @endisset

        @empty($list->picname)
        <div class="layui-form-item">
            <label class="layui-form-label">ICO:</label>
            <div class="layui-input-block">
                <input type="file" name="picname" lay-ext="jpg|png|gif" required lay-verify="required">
            </div>
        </div>
        @endisset
        <div class="layui-form-item" style="margin-top:10px">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="adminrole_submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('script')
    <script>

        layui.use(['element','form','layer','layedit','upload'], function(){
            var element = layui.element;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            form.on('submit(adminrole_submit)', function (data) {
                return post(data.form);
            });
            // //监听提交
            // form.on('submit(adminrole_submit)', function(data){
            //     var data = data.field;
            //     $.ajax({
            //         url:'{{url('admin/type_insert')}}'
            //         ,type:'post'
            //         ,dataType:'json'
            //         ,data: data
            //         ,success:function (res) {
            //             layer.msg(res.data);
            //             if(res.code == 200) {
            //                 var index = parent.layer.getFrameIndex(window.name);
            //                 parent.layer.close(index);
            //                 parent.window.location.reload();
            //             }else{
            //                 return false;
            //             }
            //         }
            //     });
            //     return false;
            // });
        });

        // 表单的提交事件
        var post = function(obj){
            // console.log(obj);return ;
            $(obj).ajaxSubmit({
                success: function(data){
                    console.log(data);
                    layer.msg(data.data);
                    if(data.code == 200){
                        // layer.close(index);
                        // layer.closeAll();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.window.location.reload();
                        // window.location.reload();
                    }else{
                        layer.msg(data.data);
                    }
                }
            });
            return false;
        }
    </script>
@endsection